//
//  OrderTableViewCell.swift
//  worldexchange
//
//  Created by xionghao on 2019/2/18.
//  Copyright © 2019 xionghao. All rights reserved.
//

import UIKit

class OrderTableViewCell: QMUITableViewCell {
    
    @IBOutlet weak var stateLabel: UILabel!
    
    var item:OrderItem! {
        didSet {
            refreshView()
        }
    }
    
    func refreshView() {
        self.tvOrderNO.text = "NO." + self.item.link
        self.tvTime.text = self.item.date
        self.tvPirce.text = self.item.money
        self.tvRate.text = self.item.ones
        self.tvExchange.text = self.item.title
        self.tvReservation.text = self.item.ex_title
        self.tvBranch.text = self.item.address
        self.stateLabel.isHidden = self.item.is_verify == 0
        self.tvType.text = self.item.type == 0 ? LanguageHelper.getString(key: "buyRateBtnLabel") : LanguageHelper.getString(key: "sellRateBtnLabel")
        let moneyValue = self.tvPirce.text ?? ""
        var money = 0.00
        if moneyValue == "" {
            money = 0.00
        } else {
            money = Double(moneyValue) ?? 0.00
        }
        let rate = Double(self.tvRate.text!)!
        
        let total = self.item.type == 0 ? rate * money : money / rate
        self.tvMoney.text = String(format: "%.2f", total)
    }
    
    @IBOutlet weak var tvOrderNO: UILabel!
    @IBOutlet weak var tvPriceTips: UILabel!
    @IBOutlet weak var tvPirce: UILabel!
    @IBOutlet weak var tvBranchTips: UILabel!
    @IBOutlet weak var tvBranch: UILabel!
    @IBOutlet weak var tvRateTips: UILabel!
    
    @IBOutlet weak var tvRate: UILabel!
    @IBOutlet weak var tvReservationTips: UILabel!
    @IBOutlet weak var tvReservation: UILabel!
    @IBOutlet weak var tvExcahngeTips: UILabel!
    @IBOutlet weak var tvExchange: UILabel!
    @IBOutlet weak var tvTypeTips: UILabel!
    
    @IBOutlet weak var tvMoneyTips: UILabel!
    @IBOutlet weak var tvType: UILabel!
    @IBOutlet weak var tvTimeTips: UILabel!
    @IBOutlet weak var tvTime: UILabel!
    
    @IBOutlet weak var tvMoney: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.tvPriceTips.text = LanguageHelper.getString(key: "textPrice")
        self.tvBranchTips.text = LanguageHelper.getString(key: "textBranch")
        self.tvExcahngeTips.text = LanguageHelper.getString(key: "textExchange")
        self.tvReservationTips.text = LanguageHelper.getString(key: "textReservation")
        self.tvRateTips.text = LanguageHelper.getString(key: "textRate")
        self.tvTypeTips.text = LanguageHelper.getString(key: "textType")
        self.tvTimeTips.text = LanguageHelper.getString(key: "textTime")
        self.tvMoneyTips.text = "可换金额".localized()
self.stateLabel.text = LanguageHelper.getString(key: "预约成功")
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
